package com.pcbly.web.components.utils.template.dao;

import java.io.File;
 
import com.pcbly.web.bean.user.*;
import com.pcbly.web.components.utils.ClassUtilsStatic;
import com.pcbly.web.components.utils.template.ModelPrint;

public class ModelCommonDaos extends ModelPrint {
	

	public void execute(Class<?> clz) {
		try {
			String pachageString = clz.getPackage().getName();
			String path = pachageString.replaceAll("\\.", "/");
			String pacha = clz.getPackage().getName();
			File file = new File("src/" + path);
			String midTable = pacha.substring(pacha.lastIndexOf(".") + 1, pacha
					.length());
			midTable = "t_" + midTable + "_";
			String tableName;
			if (file.isDirectory()) {
				String[] files = file.list();
				for (String tfile : files) {
					if (tfile.indexOf("java") >= 0) {
						String te = tfile.substring(0, tfile.indexOf("."));
						tableName = midTable + ""
								+ te.substring(0, te.length() - 4);
						tableName = tableName.toLowerCase();
						// System.out.println(tableName);

						te = pacha + "." + te;

						// System.out.println(te);

						ModelCommonDao dao = new ModelCommonDao();
						Class<?> temp = ClassUtilsStatic.forName(te);
						dao.setTableName(tableName);
						dao.setPrint(print);
						dao.execute(temp);
					}
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		System.out.println("begin...................");
		ModelCommonDaos dao = new ModelCommonDaos();
		dao.setPrint(true);
		dao.execute(UserBean.class);
		System.out.println("end...................");
	}
}
